<template>
  <div class="app-container">
    <!--工具栏-->
    <div>
      <!-- 搜索 -->
      <el-input v-model="query.blurry" clearable size="small" placeholder="姓名，身份证" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
      <date-range-picker v-model="query.bisJsxxJssj" class="date-item" />
      <rrOperation :crud="crud" />
    </div>
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="主键ID" prop="bisJsxxId">
            <el-input v-model="form.bisJsxxId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="照护ID">
            <el-input v-model="form.bisJsxxZhid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="就诊ID">
            <el-input v-model="form.bisJsxxJzid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="form.bisJsxxXm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="身份证">
            <el-input v-model="form.bisJsxxSfz" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="就诊流水号">
            <el-input v-model="form.bisJsxxLsh" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结算时间">
            <el-input v-model="form.bisJsxxJssj" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="医疗总费用">
            <el-input v-model="form.bisJsxxYlzfy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="统筹支付金额">
            <el-input v-model="form.bisJsxxTczf" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="个人现金支付">
            <el-input v-model="form.bisJsxxGrxj" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据号(发票号)">
            <el-input v-model="form.bisJsxxDjh" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="统筹段自付比例">
            <el-input v-model="form.bisJsxxTcbl" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="医疗机构名称">
            <el-input v-model="form.bisJsxxYljgmc" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="医疗机构编码">
            <el-input v-model="form.bisJsxxYljgbm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="医保卡号">
            <el-input v-model="form.bisJsxxYbkh" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否退费">
            <el-input v-model="form.bisJsxxSftf" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退费时间">
            <el-input v-model="form.bisJsxxTfsj" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="bisJsxxXm" label="姓名" />
        <el-table-column prop="bisJsxxYbkh" label="医保卡号" />
        <el-table-column prop="bisJsxxSfz" label="身份证" width="130px" />
        <el-table-column prop="bisJsxxJssj" label="结算时间" width="130px" />
        <el-table-column prop="bisJsxxYlzfy" label="医疗总费用" />
        <el-table-column prop="bisJsxxTczf" label="统筹支付金额" />
        <el-table-column prop="bisJsxxGrxj" label="个人现金支付" />
        <el-table-column prop="bisJsxxTcbl" label="统筹段自付比例" />
        <el-table-column prop="bisJsxxRyrq" label="入院日期" />
        <el-table-column prop="bisJsxxCyrq" label="出院日期" />
        <el-table-column prop="bisJsxxSftf" label="是否退费" />
        <el-table-column prop="bisJsxxTfsj" label="退费时间" />
        <el-table-column
          fixed="right"
          label="操作"
          width="120"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click.native.prevent="toOpen(scope.row)"
            >
              预 览
            </el-button>
            <el-button
              type="text"
              size="small"
              @click.native.prevent="doQftf(scope.$index, scope.row)"
            >
              清方退费
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <!-- 打印拨付单 -->
      <printView ref="printView" />
    </div>
  </div>
</template>

<script>
import printView from '../jsxx/printView'
import crudJsxx from '@/api/business/jsxx'
import crudJzdj from '@/api/business/jzdj'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import moment from 'moment'
import DateRangePicker from '@/components/DateRangePicker'

const defaultForm = { bisJsxxId: null, bisJsxxZhid: null, bisJsxxJzid: null, bisJsxxXm: null, bisJsxxSfz: null, bisJsxxLsh: null, bisJsxxJssj: null, bisJsxxYlzfy: null, bisJsxxTczf: null, bisJsxxGrxj: null, bisJsxxDjh: null, bisJsxxTcbl: null, bisJsxxYljgmc: null, bisJsxxYljgbm: null, bisJsxxYbkh: null, bisJsxxSftf: null, bisJsxxTfsj: null }
export default {
  name: 'Jsxx',
  components: { pagination, crudOperation, rrOperation, udOperation, printView, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '结算信息', url: 'api/bisJsxx', idField: 'bisJsxxId', sort: 'bisJsxxJssj,desc', crudMethod: { ...crudJsxx }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'jsxx:add'],
        edit: ['admin', 'jsxx:edit'],
        del: ['admin', 'jsxx:del']
      },
      rules: {
        bisJsxxId: [
          { required: true, message: '主键ID不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    /**
     * 查询打印
     * @param index
     * @param rows
     */
    toOpen(row) {
      this.$refs.printView.printViewDialog = true
      this.$refs.printView.dataValue = row
      this.$refs.printView.tempAae002 = moment(row.aae002).format('YYYY年MM月DD日')
    },
    /**
     * 清方退费
     * @param index
     * @param rows
     */
    doQftf(index, rows) {
      if (rows.bisJsxxSftf === '1') {
        this.$notify({
          title: '已经退过费了',
          type: 'success',
          duration: 2500
        })
        return
      }
      this.$confirm('确定退费吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.fullscreenLoading = true
        crudJzdj.exeQftf({ jzid: rows.bisJsxxJzid, jsxxId: rows.bisJsxxId })
          .then(res => {
            this.fullscreenLoading = false
            this.$notify({
              title: '已退费',
              type: 'success',
              duration: 2500
            })
            console.log(res)
          })
          .catch(err => {
            this.fullscreenLoading = false
            this.$notify({
              title: err,
              type: 'warning',
              duration: 2500
            })
          })
      })
    }
  }
}
</script>

<style scoped>

</style>
